<!--
 * @Author: 花香蝶自来 1026583651@qq.com
 * @Date: 2024-04-16 18:35:31
 * @LastEditors: zhangxiangsheng 1026583651@qq.com
 * @LastEditTime: 2024-05-30 15:25:23
 * @FilePath: \shop\components\tabbar\tabbar.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <view>
    <u-tabbar
      :value="value"
      @change="change"
      :fixed="true"
      :placeholder="true"
      :safeAreaInsetBottom="true"
    >
      <u-tabbar-item
        v-for="(item,index) in list"
        :text="item.text"
		:key="index"
        :icon="item.icon"
      ></u-tabbar-item>
    </u-tabbar>
  </view>
</template>

<script>
  export default {
    name: "tabbar",
    data() {
      return {
        value: "0",
        imgs1: [
          "f2736f645ea742a8a1088aea7882f1dc.png",
          "44322a64739d46598f8fd5783ebc40be.png",
          "d974dc7189fc4ab5aea8643d55638957.png",
          "8c72187e08eb4f86b7515047b9ef9e17.png",
        ],
        imgs2: [
          "3ec48213957148e6b04114e9d84b204d.png",
          "6b1435c0206243c2b1f034c2a0e9feb2.png",
          "714f402231794933bb3788d5ed5f1401.png",
          "281f5b5166fd4d3690e4f19c5860f1a3.png",
        ],
      };
    },
    computed: {
      list() {
        let v = this.value;
        let r = [
          {
            text: "首页",
            page: "/pages/home/index",
          },
          {
            text: "分类",
            page: "/pages/cate/index",
          },
          {
            text: "购物车",
            page: "/pages/shop/index",
          },
          {
            text: "我的",
            page: "/pages/index/index",
          },
        ].map((e, i) => {
          let img = this.imgs1[i];
          if (v == i) {
            img = this.imgs2[i];
          }
          return {
            ...e,
            icon: this.$z.imgsrc(img),
          };
        });
        return r;
      },
    },

    module() {},
    mounted() {
      this.init();
    },
    // ready
    methods: {
      init() {
        let pages = getCurrentPages();
        console.log(pages);
        let fullPath = pages[pages.length - 1].$page.fullPath;
        let i = this.list.findIndex((e) => {
          return e.page == fullPath;
        });
        this.value = String(i);
      },
      change(item) {
        // this.value = item
        let dqitem = this.list[item];
        uni.reLaunch({
          url: dqitem.page,
        });
        console.log(item, this.value);
      },
    },
  };
</script>

<style></style>
